<?php
header("Content-Type: text/html; charset=UTF-8");
class categorylistmodel extends CI_Model {

	var $title   = '';
	var $content = '';
	var $date    = '';

	var $xmlPath;	
	
	function setXmlPath($xmlPath){
		$this->xmlPath = $xmlPath;
	}

	function categorylist($xmlPath)
	{	
		
		//오픈 api설정
		//$url = 'http://api.danawa.com/api/main/category/product/list?charset=utf8&key=fd25bbfcb76e369ecabc6e7690028f4c&cate1=861&cate2=873&orderBy=saveCountDESC&limit=10&offset=0';
		try {
			$xml = simpleXML_load_file($xmlPath, "SimpleXMLElement", LIBXML_NOCDATA );
			
		} catch (Exception $e) {
			echo "잘못된경로";
		}		
		
		if($xml ===  FALSE)
		{
			echo "에러";
		}
		else {
			echo "성공";
			$resultList=array();
			foreach($xml->productCategory as $child){
				 $list=array();
				// $list[''] = $child->product->code;
				 $list['cate1']=$child->cateCode1;
				 $list['cate2']=$child->cateCode2;
				 $list['code'] =$child->product->code;
				 $list['name'] = $child->product->name;
				 $list['minPrice'] = $child->product->minPrice;
				 $list['avgPrice'] = $child->product->avgPrice;
				 $list['madeDate'] = $child->product->makeDate;
				 $list['shopCount'] = $child->product->shopCount;
				// $list[''] = $child->product->shortageYN."<br/>";
				 $list['option'] = $child->product->productSimpleDescription->importantOptionString."<br/>";
				 $list['makeCode'] = $child->product->maker->code;
				 $list['makeName'] = $child->product->maker->name."<br/>";
				// $list[''] = $child->product->brand->code;
				// $list[''] = $child->product->brand->makerCode;
				 $list['brandName'] = $child->product->brand->name."<br/>";
				 $list['viewBit'] = $child->viewBit."<br/>";
				// $list[''] = $child->saveQuantity."<br/>";
				 $list['image'] = "<img src='".$child->image_url."'/><br/>";		
				 
				 $resultList[]=$list;
			}
		if($resultList==null){
			echo "<br/>잘못된코드";
			exit();
		}else{
		return $resultList;
		}
		}
	
	}
	
	
	function category($xmlPath){
		$xml = simpleXML_load_file($xmlPath, "SimpleXMLElement", LIBXML_NOCDATA );
		
		
		if($xml ===  FALSE)
		{
			echo "에러";
		}
		else {
			echo "성공";
			
			$list= array();
			$list['cate1']= $xml->productCategory->cateCode1;
			$list['cate2']= $xml->productCategory->cateCode2;
			$list['name']= $xml->name." ";
			$list['bundleName']= $xml->bundleName." ";
			 $list['minPrice']=$xml->minPrice." ";
			 $list['avgPrice']=$xml->avgPrice."<br/>";
			 $list['makeDate']=$xml->makeDate." ";
			 $list['inputDate']=$xml->inputDate." ";
			 $list['modifyDate']=$xml->modifyDate." ";
			 $list['shopCount']=$xml->shopCount."<br/>";
			 $list['writeCnt']=$xml->productBoardCount->writeCnt."<br/>";
		
			//print_r($child->images);
			foreach ($xml->images->image as $var){
				 $list['image']="<img src='".$var->url."'/>";
			}
		
			 $list['importantOptionString']="<br/>".$xml->productSimpleDescription->importantOptionString." ";
			 $list['etcOptionString']=$xml->productSimpleDescription->etcOptionString."<br/>";
			 $list['htmlDescription']=$xml->contents->htmlDescription."<br/>";
			 $list['size']=$xml->contents->size."<br/>";
			 $list['inputDate']=$xml->contents->inputDate."<br/>";
			 $list['modifyDate']=$xml->contents->modifyDate."<br/>";
			 $list['mName']=$xml->maker->name."<br/>";
			 $list['bName']=$xml->brand->name."<br/>";
		
			 
			
		}
		
		return $list;
	}


}
?>